<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<!-- HTML file produced from file: manual.tex --
 -- using Hyperlatex v 2.3.1 (c) Otfried Cheong--
 -- on Emacs 21.4 (patch 12) "Portable Code" XEmacs Lucid, Wed Jun  2 18:57:00 2004 -->
<HEAD>
<TITLE>Scheme 48 Manual -- Port extensions</TITLE>

</HEAD><BODY BGCOLOR="#ffffff">
<EM>Scheme 48 Manual</EM> | <A HREF="s48manual.html#top_node">Contents</A> | In Chapter: <A HREF="s48manual_35.html">Libraries</A><BR>Previous: <A HREF="s48manual_49.html">Port extensions</A> | Next: <A HREF="s48manual_49.html">Port extensions</A>
<H2>Port extensions</H2>
<P>These procedures are in structure <CODE>extended-ports</CODE>.
<P><UL><LI><CODE>(make-string-input-port<I>&nbsp;string</I>)&nbsp;-&gt;&nbsp;<I>input-port</I></CODE><A NAME="1">&nbsp;</A>
<LI><CODE>(make-string-output-port<I></I>)&nbsp;-&gt;&nbsp;<I>output-port</I></CODE><A NAME="2">&nbsp;</A>
<LI><CODE>(string-output-port-output<I>&nbsp;string-output-port</I>)&nbsp;-&gt;&nbsp;<I>string</I></CODE><A NAME="3">&nbsp;</A>
</UL>
<CODE>Make-string-input-port</CODE> returns an input port that
 that reads characters from the supplied string.  An end-of-file
 object is returned if the user reads past the end of the string.
<CODE>Make-string-output-port</CODE> returns an output port that saves
 the characters written to it.
These are then returned as a string by <CODE>string-output-port-output</CODE>.
<P><BLOCKQUOTE><PRE>
(read (make-string-input-port "(a b)"))
    <CODE>-&gt;</CODE> '(a b)

(let ((p (make-string-output-port)))
  (write '(a b) p)
  (let ((s (string-output-port-output p)))
    (display "c" p)
    (list s (string-output-port-output p))))
    <CODE>-&gt;</CODE> '("(a b)" "(a b)c")
</PRE></BLOCKQUOTE>
<P><UL><LI><CODE>(limit-output<I>&nbsp;output-port&nbsp;n&nbsp;procedure</I>)</CODE><A NAME="4">&nbsp;</A>
</UL>
<I>Procedure</I> is called on an output port.
Output written to that port is copied to <I>output-port</I> until <I>n</I>
 characters have been written, at which point <CODE>limit-output</CODE> returns.
If <I>procedure</I> returns before writing <I>n</I> characters, then
 <CODE>limit-output</CODE> also returns at that time, regardless of how many
 characters have been written.
<P><UL><LI><CODE>(make-tracking-input-port<I>&nbsp;input-port</I>)&nbsp;-&gt;&nbsp;<I>input-port</I></CODE><A NAME="5">&nbsp;</A>
<LI><CODE>(make-tracking-output-port<I>&nbsp;output-port</I>)&nbsp;-&gt;&nbsp;<I>output-port</I></CODE><A NAME="6">&nbsp;</A>
<LI><CODE>(current-row<I>&nbsp;port</I>)&nbsp;-&gt;&nbsp;<I>integer&nbsp;or&nbsp;<TT>&nbsp;#f</TT></I></CODE><A NAME="7">&nbsp;</A>
<LI><CODE>(current-column<I>&nbsp;port</I>)&nbsp;-&gt;&nbsp;<I>integer&nbsp;or&nbsp;<TT>&nbsp;#f</TT></I></CODE><A NAME="8">&nbsp;</A>
<LI><CODE>(fresh-line<I>&nbsp;output-port</I>)</CODE><A NAME="9">&nbsp;</A>
</UL>
<CODE>Make-tracking-input-port</CODE> and <CODE>make-tracking-output-port</CODE>
 return ports that keep track of the current row and column and
 are otherwise identical to their arguments.
Closing a tracking port does not close the underlying port.
<CODE>Current-row</CODE> and <CODE>current-column</CODE> return
  <I>port</I>'s current read or write location.
They return <CODE>#f</CODE> if <I>port</I> does not keep track of its location.
<CODE>Fresh-line</CODE> writes a newline character to <I>output-port</I> if
 <CODE>(current-row <CODE><I>port</I></CODE>)</CODE> is not 0.
<P><BLOCKQUOTE><PRE>
(define p (open-output-port "/tmp/temp"))
(list (current-row p) (current-column p))
    <CODE>-&gt;</CODE> '(0 0)
(display "012" p)
(list (current-row p) (current-column p))
    <CODE>-&gt;</CODE> '(0 3)
(fresh-line p)
(list (current-row p) (current-column p))
    <CODE>-&gt;</CODE> '(1 0)
(fresh-line p)
(list (current-row p) (current-column p))
    <CODE>-&gt;</CODE> '(1 0)
</PRE></BLOCKQUOTE>
<P><P>
  
Previous: <A HREF="s48manual_49.html">Port extensions</A> | Next: <A HREF="s48manual_49.html">Port extensions</A></BODY></HTML>
